package universe;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Set;
import java.util.TreeSet;

import app.Configuration;

public class Dense implements IUniverseOfDiscourse {

	private Configuration config = Configuration.getInstance();
	
	private Set<Double> elements = new TreeSet<>();
	private double step = config.getDenseToDiscreteStep();
	
	private double minBoundary = 0.0;
	private double maxBoundary = 0.0;
	
	public Dense() {
	}
	
	public Dense(double min, double max) {
		minBoundary = min;
		maxBoundary = max;
		
		//addInterval(min, max);
	}
	
	@Override
	public Set<Double> getElements() {
		return elements;
	}
	
	@Override
	public Boolean isExists(double element) {
		return elements.contains(element);
	}
	
	public void addInterval(double min, double max) {
		DecimalFormatSymbols symbols = new DecimalFormatSymbols();
		symbols.setDecimalSeparator('.');
		DecimalFormat format = new DecimalFormat("#.####", symbols);		// BUGFIX
		for (double i = min; i <= max; i += step) {
			//elements.add(i);	// BUG HERE
			elements.add(Double.valueOf(format.format(i)));		// BUGFIX
		}
		
		minBoundary = min;
		maxBoundary = max;
	}

	@Override
	public double getMinBoundary() {
		return minBoundary;
	}

	@Override
	public double getMaxBoundary() {
		return maxBoundary;
	}

}
